package com.cskaoyan.shopping.service.remote;

import com.cskaoyan.mall.dto.*;
import com.cskaoyan.shopping.converter.ProductConverter;
import com.cskaoyan.shopping.dal.entitys.Item;
import com.cskaoyan.shopping.dal.persistence.ItemMapper;
import com.cskaoyan.shopping.service.ICartService;
import com.cskaoyan.shopping.service.IDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @auther cskaoyan
 * @date 2022/6/16:16:33
 */

/*
   服务与服务之间的调用有关系
 */
@RestController
public class OrderProductServiceImpl{

    @Autowired
    ICartService iCartSevice;

    @Autowired
    ItemMapper itemMapper;

    @Autowired
    ProductConverter productConverter;

    @Autowired
    IDetailService iDetailService;

    @RequestMapping(value = "/rpc/items",method = RequestMethod.DELETE)
    public ClearCartItemResponse clearCartItemByUserID(@RequestBody ClearCartItemRequest request) {
        return iCartSevice.clearCartItemByUserID(request);
    }

    @PostMapping(value = "/promo/rpc/detail")
    public ProductDetailResponse getProductDetail(@RequestBody ProductDetailRequest request) {
        return iDetailService.getProductDetail(request);
    }

    @PostMapping(value = "/order/rpc/detail")
    public ProductDetailResponse getOrderProductDetail(@RequestBody ProductDetailRequest request) {
        return iDetailService.getProductDetail(request);
    }

    @GetMapping("/rpc/items")
    public AllItemResponse getAllProductItem() {
        AllItemResponse allItemResponse = new AllItemResponse();
        List<Item> items = itemMapper.selectAll();
        List<ItemDto> itemDtos = productConverter.items2ItemDtos(items);
        allItemResponse.setAllItems(itemDtos);
        return allItemResponse;
    }

}
